/*
** SMSE2k sound device interface factory and CBaseSoundDevice
*/

#include <stdio.h>
#include <string.h>

#include "smse2kincludes.h"
#include "sounddevice.h"
#include "sounddevicefactory.h"


static CSoundDeviceFactory* factories[256];
static int factorycount = 0;

void RegisterSoundDeviceFactory(CSoundDeviceFactory* factory) {
	if (!factory) return;

	// Catch unknown interface versions
	if (factory->GetInterfaceVersion() > SOUND_INTERFACE_CURRENT_VERSION) {
		Msg("Couldn't register sound factory for device %s: Invalid version %d, check source for problems\n",
					factory->GetName(), factory->GetInterfaceVersion());
		return;
	}


	Msg("New sound Device: %s. (Interface version %d)\n",factory->GetName(),factory->GetInterfaceVersion());

	factories[factorycount] = factory;
	factorycount ++;
}

ISoundDevice* SoundDeviceFactory (const char* type) {
	for (int i=0;i<factorycount;i++) {
		if (!strcmpi(factories[i]->GetName(),type))
			return factories[i]->Init();
	}

	Msg("WARNING! Unknown sound device \"%s\" requested!\n",type);
	return NULL;
}

void OutputSNDList() {
	Msg("Sound devices in SoundDeviceFactory:\n");
	for (int i=0;i<factorycount;i++) {
		Msg("%d. %s\n",i+1,factories[i]->GetName());
	}

}